home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 7 / Amiga Format AFCD07 (Dec 1996, Issue 91).iso / serious / shareware / programming / gamesmaster / source / asm / demos / julia.s next >
Encoding:
Text File  |  1996-09-08  |  7.8 KB  |  354 lines

  1. ;JULIA 2
  2. ;-------
  3. ;A fractal generator, not orginally written by myself but now works with
  4. ;the library.
  5.  
  6.     opt    o+
  7.  
  8.     INCLUDE    "exec/exec_lib.i"
  9.     INCLUDE    "games/games_lib.i"
  10.     INCLUDE    "games/games.i
  11.     INCLUDE    "hardware/custom.i"
  12.  
  13. CALL    MACRO
  14.     jsr    _LVO\1(a6)
  15.     ENDM
  16.  
  17. SAVEREGS MACRO
  18.     MOVEM.L    A0-A6/D0-D7,-(SP)
  19.     ENDM
  20.  
  21. RETURNREGS MACRO
  22.     MOVEM.L    (SP)+,A0-A6/D0-D7
  23.     ENDM
  24.  
  25.     SECTION    "Julia",CODE
  26.  
  27. ;==========================================================================;
  28. ;                             INITIALISE DEMO
  29. ;==========================================================================;
  30.  
  31. Start:    MOVEM.L    A0-A6/D1-D7,-(SP)
  32.     move.l    ($4).w,a6
  33.     lea    GMS_Name(pc),a1
  34.     moveq    #$00,d0
  35.     CALL    OpenLibrary
  36.     move.l    d0,GMS_Base
  37.     beq    Quit
  38.  
  39.     move.l    GMS_Base(pc),a6
  40.     CALL    SetUserPri
  41.  
  42.     move.l    GMS_Base(pc),a6          ;Tell GMS that we want to add a
  43.     lea    ScreenStruct(pc),a0      ;screen for use.
  44.     CALL    Add_Screen
  45.     tst.l    d0
  46.     bne    Error
  47.  
  48.     lea    ScreenStruct(pc),a0      ;Now show the screen/pic.
  49.     CALL    Show_Screen
  50.  
  51. ;==========================================================================;
  52. ;
  53. ;==========================================================================;
  54.  
  55.     lea    DataArea(pc),a5
  56.     move.l    #$fffffffe,(a5)+         ;a5 = $fffffffe+
  57.     move.l    #$80000014,(a5)+         ;a5 = mask & word per raster count
  58.  
  59. StartJulia:
  60.     move.l    ScreenStruct+SS_MemPtr1(pc),a0 ;get pointer to bitplanes
  61.  
  62. .waitb    btst.b    #6,$dff000+dmaconr
  63.     bne.b    .waitb
  64.     move.l    a0,$dff000+bltdpt
  65.     move.l    #$01000000,$dff000+bltcon0
  66.     clr.w    $dff000+bltdmod
  67.     move.w    #(640*64)+40,$dff000+bltsize ;256*40*5 bytes
  68.  
  69.     lea    JuliaData(pc),a6
  70.     move.l    (a6)+,(a5)               ;a5 = ?
  71.  
  72. .JuliaFound
  73.     move.w    (a5),MValue              ;initial m
  74.     move.w    (a6),PixStep             ;pixel step
  75.     move.w    (a6)+,RastStep           ;raster step
  76.     move.l    (a6)+,C1C2               ;initial c1 and c2
  77.     move.w    #256,LinesLeft(a5)       ;vertical height
  78.     lea    256*40(a0),a1
  79.     lea    256*40(a1),a2
  80.     lea    256*40(a2),a3
  81.     lea    $04000000,a6             ;for magnitude test
  82.  
  83.     lea    256*40(a3),a4
  84.  
  85.     MOVE.L    A6,-(SP)
  86.     move.l    GMS_Base(pc),a6
  87.     CALL    Wait_OSVBL
  88.     MOVE.L    (SP)+,A6
  89.  
  90. PixelLoop:
  91.     move.w    (a5),d1                  ;d1 = Initial X
  92.     move.w    InitialY(a5),d0          ;d0 = Initial Y
  93.     moveq    #30,d7                   ;d7 = 30.
  94.     movem.w    C1C2(pc),d4-d5           ;MA : d4/d5 = C1/C2
  95.     move.w    d0,d2                    ;d2 = Initial Y
  96.     move.w    d1,d3                    ;d3 = Initial X
  97.     bra.s    CheckMagnitude
  98.  
  99. IterateJulia:
  100.     sub.l    d3,d2                    ;x^2 - y^2
  101.     lsl.l    #4,d2                    ;fix decimal point
  102.     swap    d2                       ;...
  103.     add.w    d4,d2                    ;x1 = x^2 - y^2 + c1
  104.  
  105.     move.w    d1,d3                    ;y
  106.     muls    d0,d3                    ;x * y
  107.     lsl.l    #5,d3                    ;fix decimal point and multiply by 2
  108.     swap    d3                       ;...
  109.     add.w    d5,d3                    ;y1 = 2 * x * y + c2
  110.  
  111.     move.w    d2,d0                    ;x = x1
  112.     move.w    d3,d1                    ;y = y1
  113.  
  114. CheckMagnitude:
  115.     muls    d2,d2                    ;x^2
  116.     muls    d3,d3                    ;y^2
  117.     move.l    d2,d6
  118.     add.l    d3,d6                    ;z = x^2 + y^2
  119.     cmp.l    a6,d6                    ;escaped yet?
  120.     dbhi    d7,IterateJulia
  121.     move.w    PixelMask(a5),d6
  122.     moveq    #0,d5
  123.     move.b    JumpTable+1(pc,d7.w),d5
  124.     jmp    JumpTable(pc,d5.w)
  125.  
  126. JumpTable:
  127.     dc.b    Plot00-JumpTable,Plot31-JumpTable
  128.     dc.b    Plot30-JumpTable,Plot29-JumpTable
  129.     dc.b    Plot28-JumpTable,Plot27-JumpTable
  130.     dc.b    Plot26-JumpTable,Plot25-JumpTable
  131.     dc.b    Plot24-JumpTable,Plot23-JumpTable
  132.     dc.b    Plot22-JumpTable,Plot21-JumpTable
  133.     dc.b    Plot20-JumpTable,Plot19-JumpTable
  134.     dc.b    Plot18-JumpTable,Plot01-JumpTable
  135.     dc.b    Plot16-JumpTable,Plot15-JumpTable
  136.     dc.b    Plot14-JumpTable,Plot13-JumpTable
  137.     dc.b    Plot12-JumpTable,Plot11-JumpTable
  138.     dc.b    Plot10-JumpTable,Plot09-JumpTable
  139.     dc.b    Plot08-JumpTable,Plot07-JumpTable
  140.     dc.b    Plot06-JumpTable,Plot05-JumpTable
  141.     dc.b    Plot04-JumpTable,Plot03-JumpTable
  142.     dc.b    Plot02-JumpTable,Plot17-JumpTable
  143.  
  144. Plot22:    or.w    d6,(a4)
  145.     or.w    d6,(a2)
  146.     or.w    d6,(a1)
  147.     bra.b    Plot00
  148.  
  149. Plot21:    or.w    d6,(a4)
  150.     or.w    d6,(a2)
  151.     or.w    d6,(a0)
  152.     bra.b    Plot00
  153.  
  154. Plot20:    or.w    d6,(a4)
  155.     or.w    d6,(a2)
  156.     bra.b    Plot00
  157.  
  158. Plot18:    or.w    d6,(a4)
  159.     or.w    d6,(a1)
  160.     bra.b    Plot00
  161.  
  162. Plot26:    or.w    d6,(a4)
  163. Plot10:    or.w    d6,(a3)
  164.     or.w    d6,(a1)
  165.     bra.b    Plot00
  166.  
  167. Plot23:    or.w    d6,(a4)
  168.     or.w    d6,(a2)
  169.     or.w    d6,(a1)
  170.     or.w    d6,(a0)
  171.     bra.b    Plot00
  172.  
  173. Plot19:    or.w    d6,(a4)
  174.     or.w    d6,(a1)
  175.     or.w    d6,(a0)
  176.     bra.b    Plot00
  177.  
  178. Plot27:    or.w    d6,(a4)
  179. Plot11:    or.w    d6,(a3)
  180.     or.w    d6,(a1)
  181.     or.w    d6,(a0)
  182.     bra.b    Plot00
  183.  
  184. Plot17:    or.w    d6,(a4)
  185.     or.w    d6,(a0)
  186.     bra.b    Plot00
  187.  
  188. Plot25:    or.w    d6,(a4)
  189. Plot09:    or.w    d6,(a3)
  190.     or.w    d6,(a0)
  191.     bra.b    Plot00
  192.  
  193. Plot29:    or.w    d6,(a4)
  194. Plot13:    or.w    d6,(a3)
  195. Plot05:    or.w    d6,(a2)
  196.     or.w    d6,(a0)
  197.     bra.b    Plot00
  198.  
  199. Plot16:    or.w    d6,(a4)
  200.     bra.b    Plot00
  201.  
  202. Plot24:    or.w    d6,(a4)
  203. Plot08:    or.w    d6,(a3)
  204.     bra.b    Plot00
  205.  
  206. Plot28:    or.w    d6,(a4)
  207. Plot12:    or.w    d6,(a3)
  208. Plot04:    or.w    d6,(a2)
  209.     bra.b    Plot00
  210.  
  211. Plot30:    or.w    d6,(a4)
  212. Plot14:    or.w    d6,(a3)
  213. Plot06:    or.w    d6,(a2)
  214. Plot02:    or.w    d6,(a1)
  215.     bra.b    Plot00
  216.  
  217. Plot31:    or.w    d6,(a4)
  218. Plot15:    or.w    d6,(a3)
  219. Plot07:    or.w    d6,(a2)
  220. Plot03:    or.w    d6,(a1)
  221. Plot01:    or.w    d6,(a0)
  222.  
  223. Plot00:    MOVE.L    D0,-(SP)
  224.     move.w    PixStep(pc),d0
  225.     add.w    d0,(a5)                  ;pixel "step"
  226.     MOVE.L    (SP)+,D0
  227.  
  228.     ror.w    PixelMask(a5)            ;shift mask over
  229.     bpl.w    PixelLoop
  230.  
  231.     addq.w    #2,a0
  232.     addq.w    #2,a1
  233.     addq.w    #2,a2
  234.     addq.w    #2,a3
  235.     addq.w    #2,a4
  236.     subq.w    #1,WordsInRaster(a5)     ; subtract from word counter
  237.     bne.w    PixelLoop
  238.  
  239.     MOVE.L    A6,-(SP)
  240.     move.l    GMS_Base(pc),a6
  241.     CALL    AutoOSReturn
  242.     MOVE.L    (SP)+,A6
  243.  
  244.     btst.b    #6,$bfe001
  245.     beq.b    Exit
  246.  
  247.     move.w    #320/16,WordsInRaster(a5) ; words per raster
  248.     btst.b    #2,$dff016               ; new julia?
  249.     beq.b    NewJulia
  250.  
  251. RasterInit:
  252.     move.w    MValue(pc),(a5)          ; inital M value
  253. RasterAdd:
  254.     MOVE.L    D0,-(SP)
  255.     move.w    RastStep(pc),d0
  256.     add.w    d0,InitialY(a5)          ; raster "step"
  257.     MOVE.L    (SP)+,D0
  258.     subq.w    #1,LinesLeft(a5)
  259.     bne.w    PixelLoop
  260.  
  261. WaitMouse:
  262.     btst.b    #6,$bfe001
  263.     beq.b    Exit
  264.     btst.b    #2,$dff016
  265.     bne.b    WaitMouse
  266.  
  267. NewJulia:
  268.     btst.b    #2,$dff016
  269.     beq.b    NewJulia
  270.     bra.w    StartJulia
  271.  
  272. ;===========================================================================;
  273. ;                              RETURN TO DOS
  274. ;===========================================================================;
  275.  
  276. Exit:    move.l    GMS_Base(pc),a6
  277.     lea    ScreenStruct(pc),a0
  278.     CALL    Delete_Screen            ;Give back screen memory etc.
  279. Error    move.l    GMS_Base(pc),a1
  280.     move.l    ($4).w,a6
  281.     CALL    CloseLibrary
  282. Quit    MOVEM.L    (SP)+,A0-A6/D1-D7
  283.     moveq    #$00,d0
  284.     rts
  285.  
  286. ;===========================================================================;
  287. ;                                  DATA
  288. ;===========================================================================;
  289.  
  290. MValue:      dc.w    0
  291. PixStep:  dc.w    0
  292. RastStep: dc.w    0
  293. C1C2:      dc.l    0
  294.  
  295. GMS_Name:
  296.     dc.b    "games.library",0
  297.     even
  298. GMS_Base:
  299.     dc.l    0
  300.  
  301. AMT_PLANES =    5
  302.  
  303. ScreenStruct:
  304.     dc.l    "GSV1",0
  305.     dc.l    0,0,0            ;Screen_Mem1/2/3
  306.     dc.l    0                ;Screen link.
  307.     dc.l    ScreenPalette    ;Address of screen palette.
  308.     dc.l    0                ;Address of rasterlist.
  309.     dc.l    0                ;Amt of colours in palette.
  310.     dc.w    320,256,320,256  ;Screen & Pic Height/Width.
  311.     dc.w    AMT_PLANES       ;Amt_Planes
  312.     dc.w    0,0              ;Top Of Screen, X/Y
  313.     dc.w    0,0              ;X/Y counters (for scrolling).
  314.     dc.l    0                ;Special attributes.
  315.     dc.w    LORES            ;Screen mode.
  316.     dc.b    PLANAR           ;Screen type
  317.     dc.b    0                ;Reserved
  318.     even
  319.  
  320. ScreenPalette:
  321.     dc.w    $0000,$0831,$000e,$000d,$000c,$000b,$000a,$0009
  322.     dc.w    $0008,$0007,$0106,$0205,$0304,$0403,$0502,$0611
  323.     dc.w    $0720,$000f,$0942,$0a53,$0b64,$0c75,$0d86,$0c97
  324.     dc.w    $0ba8,$0a9a,$098b,$0879,$0767,$0555,$0343,$0131
  325.  
  326. JuliaData:
  327.     dc.l    $f800eb00
  328.     dc.w    $0018,$0100,$0ad0,$ec00
  329.     dc.l    $fd21eeae
  330.     dc.w    $0225,$000d,$f420,$fd43
  331.  
  332.  
  333.     dc.l    $ef000010
  334.     dc.w    $0600,$0100,$f226,$fd56
  335.  
  336.     dc.l    $0015ee00
  337.     dc.w    $fb40,$ede2,$f0b2,$001d
  338.  
  339.     dc.l    $05c0ff00
  340.     dc.w    $ef12,$e812,$001d,$f320
  341.     dc.l    $00000000
  342.  
  343.  
  344.     rsset    -4
  345. PixelMask    rs.w   1    ;mask to "OR" with bitplanes
  346. WordsInRaster    rs.w   1    ;number of words left in current raster
  347. InitialX    rs.w   1    ;inital x
  348. InitialY    rs.w   1    ;inital y
  349. LinesLeft    rs.w   1    ;number of lines left to draw
  350.  
  351.     dc.l    0
  352. DataArea:
  353.     ds.b    40
  354.